import { defineStore } from 'pinia'
import util from '@/utils/index'
import { useI18n } from 'vue-i18n';

export const useLangStore = defineStore({
    id: 'lang',
    state: () => {
      return {
        lang: '',
      }
    },
    getters: {
      getLang: (state) => {
        return state.lang
      }
    },
    actions: {
      initLang() {
        this.lang = util.getStorage('lang') || "cn";
        const { locale } = useI18n()
        locale.value = this.lang;
      },
      switchLang(lang: string) {
        this.lang = lang
        const { locale } = useI18n()
        locale.value = lang;
		    util.setStorage('lang', lang)
      }
    }
  })